/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.worlds.ui.edge;

import java.awt.Color;
import java.awt.geom.Rectangle2D;
import net.worlds.Util;
import net.worlds.ui.UI;


public class EMenu extends EFrame{
    int itemY = 0;
    int menuHeight;
    int menuWidth;
    public EMenu(String title, int x)
    {
        super(x, 23, 100, 100);
        visible = false;
        setUndecorated(true);
        fixed = true;
        setBackgroundColor(new Color(127, 136, 154));
    }
    public void setVisible(boolean v)
    {
        visible = v;
        UI.menuOpen = v;
    }
    public EMenuItem addItem(String name)
    {
        EMenuItem item = new EMenuItem(name);
        item.setX(0);
        item.setTextOffset(5);
        item.setY(itemY);
        
        int itemWidth = (int) item.getWidth() + item.getTextOffset();
        if(itemWidth + 10 > menuWidth)
            menuWidth = itemWidth + 10;
        
        item.setHeight(item.getHeight() + 6);
        int itemHeight = item.getHeight();
        itemY += itemHeight;
        menuHeight = itemY;

        addChild(7, item);
        return item;
    }
    public void calculateSize()
    {
        setWidth(menuWidth);
        setHeight(menuHeight);
        for(EComponent c : getChildren(7))
        {
            if(c instanceof EMenuItem)
            {
                ((EMenuItem)c).setWidth(menuWidth);
            }
        }
    }
    public void reset()
    {
        itemY = 0;
    }
}
